package com.fc.test.service;

import cn.hutool.core.util.StrUtil;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.ConvertUtil;
import com.fc.test.mapper.auto.HandleCaseMapper;
import com.fc.test.model.auto.HandleCase;
import com.fc.test.model.auto.HandleCaseExample;
import com.fc.test.model.auto.HandleDatail;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 服务事项 HandleCaseService
 * @Title: HandleCaseService.java 
 * @Package com.fc.test.service 
 * @author zsw_自动生成
 * @email 1345625601@qq.com
 * @date 2020-08-28 12:34:31  
 **/
@Service
public class HandleCaseService implements BaseService<HandleCase, HandleCaseExample>{
	@Autowired
	private HandleCaseMapper handleCaseMapper;
	
      	   	      	      	      	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<HandleCase> list(Tablepar tablepar,String searchText){
	        HandleCaseExample testExample=new HandleCaseExample();
	        testExample.setOrderByClause("id ASC");
	        if(StrUtil.isNotEmpty(searchText)){
	        	testExample.createCriteria().andAuthNameLike("%"+searchText+"%");
	        }
			if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
	        	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
	        }
	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<HandleCase> list= handleCaseMapper.selectByExample(testExample);
	        PageInfo<HandleCase> pageInfo = new PageInfo<HandleCase>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
					
			Integer[] integers = ConvertUtil.toIntArray(",", ids);
			List<Integer> stringB = Arrays.asList(integers);
			HandleCaseExample example=new HandleCaseExample();
			example.createCriteria().andIdIn(stringB);
			return handleCaseMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public HandleCase selectByPrimaryKey(String id) {
				
			Integer id1 = Integer.valueOf(id);
			return handleCaseMapper.selectByPrimaryKey(id1);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(HandleCase record) {
		return handleCaseMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(HandleCase record) {
				
		record.setId(null);
		
				
		return handleCaseMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(HandleCase record, HandleCaseExample example) {
		
		return handleCaseMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(HandleCase record, HandleCaseExample example) {
		
		return handleCaseMapper.updateByExample(record, example);
	}

	@Override
	public List<HandleCase> selectByExample(HandleCaseExample example) {
		
		return handleCaseMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(HandleCaseExample example) {
		
		return handleCaseMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(HandleCaseExample example) {
		
		return handleCaseMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param handleCase
	 * @return
	 */
	public int checkNameUnique(HandleCase handleCase){
		HandleCaseExample example=new HandleCaseExample();
		example.createCriteria().andAuthNameEqualTo(handleCase.getAuthName());
		List<HandleCase> list=handleCaseMapper.selectByExample(example);
		return list.size();
	}


    public void batchInsert(List<HandleCase> list) {
		handleCaseMapper.batchInsert(list);
    }

	public PageInfo<HandleCase> list2(int pageNum, int pageSize, String searchText) {
		PageHelper.startPage(pageNum, pageSize);


		HandleCaseExample testExample=new HandleCaseExample();
		testExample.setOrderByClause("id ASC");
		if(StrUtil.isNotEmpty(searchText)){
			testExample.or().andAuthNameLike("%"+searchText+"%");
		}

		PageHelper.startPage(pageNum, pageSize);
		List<HandleCase> list= handleCaseMapper.selectByExample(testExample);
		PageInfo<HandleCase> pageInfo = new PageInfo<>(list);
		return  pageInfo;
	}

	public List<HandleCase> queryByAuthNameList(List<String> authNameList) {

		return handleCaseMapper.queryByAuthNameList(authNameList);
	}
}
